﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Groups;
using VK.Comm;
using VK.Casemeet.Merchants;

namespace VK.Casemeet.Web.ShopAdmin.Groups
{
    public partial class grouplist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="团购列表",Url="#"}
            };
            if (!IsPostBack)
            {
                bindRepGroup();
            }
        }


        void bindRepGroup()
        {
            List<GroupsEntity> groups = GroupsBLL.GetGroups(txtName.Text.Trim(), AdminBLL.GetSessionAdmin().ShopID);
            if (groups == null || groups.Count == 0)
            {
                rptGroup.DataSource = null;
                rptGroup.DataBind();
                return;
            }

            rptGroup.DataSource = groups;
            rptGroup.DataBind();
        }

        protected void rptLine_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                switch (e.CommandName)
                {
                    case "Delete":
                        if (GroupsBLL.DelGroup(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                            Message.Msg(this.Page, CS.MsgDelSuccess, MessageType.Success);
                        }
                        else
                        {
                            Message.Msg(this.Page, CS.MsgDelFailure, MessageType.Failure);
                        }
                        break;
                }
                bindRepGroup();
            }
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            bindRepGroup();
        }
    }
}
